package user.zc.action.comp;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.function.Supplier;

public class ActionDialog extends JDialog {
    public ActionDialog(JFrame parent, String title, JScrollPane content, Supplier<Boolean> checkHandler) {
        super(parent, title, true);

        JPanel panel = new JPanel() {
           /* @Override
            public Dimension getPreferredSize() {
                return new Dimension(520, 400);
            }*/
        };
        panel.setLayout(new BorderLayout());

        panel.add(content,BorderLayout.CENTER);
        JPanel butBar = new JPanel(new FlowLayout(FlowLayout.CENTER));

        JButton yesButton = new JButton("确定");
        yesButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(checkHandler.get()){
                    dispose(); // 关闭对话框
                }
            }
        });
        butBar.add(yesButton);

        /*JButton noButton = new JButton("No");
        noButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                // 在这里处理"No"按钮的点击事件
                dispose(); // 关闭对话框
            }
        });
        butBar.add(noButton);*/

        panel.add(butBar,BorderLayout.SOUTH);
        getContentPane().add(panel);
        pack();
        setLocationRelativeTo(parent);
    }

}